package com.softwinner.awbt.common;


import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by xiasj on 17-12-20.
 */

public class BTPreference {
    private SharedPreferences mPreferences;
    private SharedPreferences.Editor mEditor;
    private static BTPreference sInstance;
    private final String NAME = "dvr";

    private final String KEY_DEVICE_NAME = "device_name";
    private final String KEY_AUTO_CONNECT = "auto_connect";
    private final String KEY_AUTO_ANSWER = "auto_answer";

    private BTPreference(Context context) {
        mPreferences = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
        mEditor = mPreferences.edit();
    }

    public static BTPreference getInstance(Context context) {
        if (sInstance == null) {
            sInstance = new BTPreference(context.getApplicationContext());
        }
        return sInstance;
    }

    public void setDeviceName(String name) {
        mEditor.putString(KEY_DEVICE_NAME, name);
        mEditor.commit();
    }

    public String getDeviceName() {
        return mPreferences.getString(KEY_DEVICE_NAME, "");
    }

    public boolean isAutoConnect() {
        return mPreferences.getBoolean(KEY_AUTO_CONNECT, false);
    }

    public void setAutoConnect(boolean isAuto) {
        mEditor.putBoolean(KEY_AUTO_CONNECT, isAuto);
    }

    public boolean isAutoAnswer() {
        return mPreferences.getBoolean(KEY_AUTO_ANSWER, false);
    }

    public void setAutoAnswer(boolean isAuto) {
        mEditor.putBoolean(KEY_AUTO_ANSWER, isAuto);
    }
}
